//---------------------------------------------------------------------------


#pragma hdrstop

#include "FileWalker.h"

//---------------------------------------------------------------------------
FileWalker::FileWalker()
{

	this->countDirs =0;
}

void FileWalker::setPath(String InputPath)
{
	if(DirectoryExists(InputPath))
	{
		this->path = InputPath;
    }else {
        throw new Exception("Ordner existiert nicht!");
    }
}

void FileWalker::searchDir()
{
	TSearchRec sr;
	String pathLokal;
	int length;
	length = this->path.Length();
	if(this->path[length] == L'/' ||this->path[length] == L'\\')
	{
		pathLokal = this->path+"*";
	}else {
	pathLokal = this->path+"\\*";
	}
  if (FindFirst(pathLokal, faDirectory, sr) == 0)
  {
	do
	{
	  if ((sr.Attr & faDirectory)  == sr.Attr && !(sr.Name == "." ||sr.Name == ".."))
	  {
		this->dirs[this->countDirs] = sr.Name;
		this->countDirs++;
	  }
	} while (FindNext(sr) == 0);
	FindClose(sr);
  }

}

String FileWalker::getPath()
{
	int length;
	length = this->path.Length();
   if(this->path[length] == L'/' ||this->path[length] == L'\\')
   {
	   return this->path;
   }else {
       return this->path+"\\";
   }
}
#pragma package(smart_init)
